<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>MOBX 的GPT</title>
    <!-- <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500&display=swap" rel="stylesheet"> -->
    <style>
        body {
            font-family: 'Roboto', sans-serif;
            margin: 0;
            padding: 0;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            background: linear-gradient(-45deg, #0f2027, #203a43, #2c5364);
            background-size: 400% 400%;
            animation: gradientBG 15s ease infinite;
            overflow-x: hidden;
            overflow-y: auto;
        }

        @keyframes gradientBG {
            0% { background-position: 0% 50%; }
            50% { background-position: 100% 50%; }
            100% { background-position: 0% 50%; }
        }

        .main-container {
            width: 95%;
            max-width: 1200px;
            display: flex;
            height: 90vh;
            min-height: 600px;
            margin: 20px auto;
            border-radius: 20px;
            overflow: hidden;
            box-shadow: 0 0 30px rgba(0, 255, 255, 0.5);
            position: relative;
            opacity: 0;
            transform: translateY(20px);
            animation: containerAppear 0.5s ease forwards;
        }

        @keyframes containerAppear {
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        @media (max-width: 768px) {
            .main-container {
                flex-direction: column;
                height: auto;
                min-height: 95vh;
            }

            .ad-container {
                display: none;
            }

            .chat-container {
                flex: 1;
            }
        }

        .main-container::before {
            content: '';
            position: absolute;
            top: -2px; left: -2px; right: -2px; bottom: -2px;
            background: linear-gradient(45deg, #00ff00, #00ffff, #ff00ff, #ffff00);
            background-size: 400%;
            border-radius: 12px;
            z-index: -1;
            opacity: 0.8;
            animation: animate 20s linear infinite, breathe 3s ease-in-out infinite;
        }

        @keyframes animate {
            0% { background-position: 0 0; }
            50% { background-position: 400% 0; }
            100% { background-position: 0 0; }
        }

        @keyframes breathe {
            0% { opacity: 0.4; box-shadow: 0 0 10px rgba(0, 255, 255, 0.2); }
            50% { opacity: 0.8; box-shadow: 0 0 20px rgba(0, 255, 255, 0.6); }
            100% { opacity: 0.4; box-shadow: 0 0 10px rgba(0, 255, 255, 0.2); }
        }

        .chat-container {
            flex: 3;
            display: flex;
            flex-direction: column;
            background-color: rgba(0, 8, 20, 0.8);
            backdrop-filter: blur(10px);
            border-right: 1px solid rgba(0, 255, 255, 0.2);
        }

        .chat-header {
            background: linear-gradient(90deg, rgba(0, 123, 255, 0.8), rgba(0, 255, 255, 0.8));
            color: #fff;
            padding: 15px;
            text-align: center;
            font-size: 1.5em;
            font-weight: 500;
            text-shadow: 0 0 10px rgba(0, 255, 255, 0.7);
            border-bottom: 1px solid rgba(0, 255, 255, 0.3);
        }

        .chat-window {
            flex: 1;
            padding: 20px;
            overflow-y: auto;
            display: flex;
            flex-direction: column;
            gap: 15px;
            scroll-behavior: smooth;
        }

        .chat-window::-webkit-scrollbar {
            width: 8px;
        }

        .chat-window::-webkit-scrollbar-track {
            background: rgba(0, 8, 20, 0.5);
            border-radius: 10px;
        }

        .chat-window::-webkit-scrollbar-thumb {
            background: linear-gradient(transparent, rgba(0, 255, 255, 0.5), transparent);
            border-radius: 10px;
        }

        .chat-window::-webkit-scrollbar-thumb:hover {
            background: linear-gradient(transparent, rgba(0, 255, 255, 0.8), transparent);
        }

        .chat-window .message {
            padding: 15px;
            border-radius: 15px;
            max-width: 70%;
            margin-bottom: 15px;
            opacity: 0;
            transform: translateY(20px);
            animation: messageAppear 0.3s ease forwards;
        }

        @keyframes messageAppear {
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        .chat-window .message.user {
            background: linear-gradient(135deg, rgba(0, 123, 255, 0.8), rgba(0, 80, 255, 0.8));
            color: #fff;
            align-self: flex-end;
            box-shadow: 0 5px 15px rgba(0, 123, 255, 0.3);
            border: 1px solid rgba(0, 255, 255, 0.3);
            backdrop-filter: blur(10px);
            transform-origin: bottom right;
        }

        .chat-window .message.bot {
            background: linear-gradient(135deg, rgba(76, 175, 80, 0.8), rgba(0, 255, 200, 0.8));
            color: #fff;
            align-self: flex-start;
            box-shadow: 0 5px 15px rgba(76, 175, 80, 0.3);
            border: 1px solid rgba(0, 255, 200, 0.3);
            backdrop-filter: blur(10px);
            transform-origin: bottom left;
        }

        .chat-input {
            display: flex;
            padding-left: 5%;
            padding-top: 10px;
            padding-bottom: 10px;
            padding-right: 5%;
            background-color: rgba(0, 8, 20, 0.8);
            width: 90%;  /* 新增 */
        }

        .chat-input input {
            flex: 1;
            padding: 15px;
            border: 2px solid rgba(0, 255, 255, 0.5);
            border-radius: 25px;
            margin-right: 15px;
            font-size: 1em;
            background-color: rgba(0, 20, 40, 0.7);
            color: #fff;
            width: calc(100% - 130px);
            transition: all 0.3s ease;
            box-shadow: 0 0 10px rgba(0, 255, 255, 0.1);
        }

        .chat-input input:focus {
            border-color: rgba(0, 255, 255, 0.8);
            box-shadow: 0 0 20px rgba(0, 255, 255, 0.2);
            outline: none;
        }

        .chat-input button {
            padding: 15px 25px;
            background: linear-gradient(90deg, rgba(76, 175, 80, 0.8), rgba(0, 255, 200, 0.8));
            color: #fff;
            border: none;
            border-radius: 25px;
            cursor: pointer;
            font-size: 1em;
            font-weight: 500;
            text-shadow: 0 0 5px rgba(255, 255, 255, 0.5);
            box-shadow: 0 0 15px rgba(0, 255, 200, 0.5);
            transition: all 0.3s ease;
            width: 100px;
            position: relative;
            overflow: hidden;
        }

        .chat-input button::before {
            content: '';
            position: absolute;
            top: 0;
            left: -100%;
            width: 100%;
            height: 100%;
            background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
            transition: 0.5s;
        }

        .chat-input button:hover {
            transform: translateY(-2px);
            box-shadow: 0 0 20px rgba(0, 255, 200, 0.8);
        }

        .chat-input button:hover::before {
            left: 100%;
        }

        .ad-container {
            flex: 1;
            background-color: rgba(0, 8, 20, 0.8);
            display: flex;
            flex-direction: column;
            justify-content: space-between;
            padding: 25px;
            border-left: 1px solid rgba(0, 255, 255, 0.2);
            backdrop-filter: blur(15px);
            transition: all 0.3s ease;
        }

        .ad-container .login-info {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 20px;
        }

        .ad-container .login-info h2 {
            font-size: 1.2em;
            margin: 0;
        }

        .ad-container .login-info button {
            padding: 8px 15px;
            background: linear-gradient(135deg, rgba(76, 175, 80, 0.9), rgba(0, 255, 200, 0.9));
            color: #fff;
            border: none;
            border-radius: 20px;
            cursor: pointer;
            font-size: 0.9em;
            font-weight: 500;
            transition: all 0.3s ease;
            box-shadow: 0 0 10px rgba(0, 255, 200, 0.3);
        }

        .ad-container .login-info button:hover {
            transform: translateY(-2px);
            box-shadow: 0 0 15px rgba(0, 255, 200, 0.5);
            background: linear-gradient(135deg, rgba(69, 160, 73, 0.9), rgba(0, 230, 180, 0.9));
        }

        .ad-container .ad-content {
            flex: 1;
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
        }

        .ad-container .ad-content h2 {
            font-size: 1.3em;
            margin-bottom: 15px;
            background: linear-gradient(135deg, #00ff00, #00ffff);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            text-shadow: 0 0 10px rgba(0, 255, 255, 0.3);
        }

        .ad-container .ad-content p {
            font-size: 1em;
            color: rgba(255, 255, 255, 0.7);
            text-align: center;
            line-height: 1.6;
            text-shadow: 0 0 5px rgba(0, 255, 255, 0.2);
        }
    </style>
</head>
<body>
<div class="main-container">
    <!-- 聊天区域 -->
    <div class="chat-container">
        <div class="chat-header">
            <h1 style="margin: 0; font-size: 1.8em; letter-spacing: 2px;">MOBX的ai智能体</h1>
        </div>
        <div class="chat-window" id="chat-window">
            <!-- 聊天内容将在这里动态显示 -->
        </div>
        <div class="chat-input">
            <input type="text" id="user-input" placeholder="请输入您要询问的内容">
            <button id="send-button">发送</button>
        </div>
    </div>

    <!-- 广告区域 -->
    <div class="ad-container">
        <!-- 登录信息 -->
        <div class="login-info">
            <h2>User: JohnDoe</h2>
            <button onclick="logout()">退出登录</button>
        </div>

        <!-- 广告内容 -->
        <div class="ad-content">
            <h2>Advertisement</h2>
            <p>This is an ad space. You can place your ads here.</p>
        </div>
    </div>
</div>

<script>
    document.addEventListener('DOMContentLoaded', () => {
        const chatWindow = document.getElementById('chat-window');
        const userInput = document.getElementById('user-input');
        const sendButton = document.getElementById('send-button');

        sendButton.addEventListener('click', () => {
            const userMessage = userInput.value.trim();
            if (userMessage) {
                // 显示用户消息
                const userMessageElement = document.createElement('div');
                userMessageElement.classList.add('message', 'user');
                userMessageElement.textContent = userMessage;
                chatWindow.appendChild(userMessageElement);

                // 模拟 GPT 回复（实际使用时可以替换为 API 请求）
                // 后期换成我的接口，写入数据库
                fetch('https://api.deepseek.com/chat/completions', {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json',
                        'Authorization':'Bearer sk-f2620290ca774c1393f8000101dd379d'
                    },
                    body:JSON.stringify({
                        "model": "deepseek-chat",
                        "messages": [
                            {"role": "system", "content": "你是一个叫MOBX AI的写代码的高手，回答请使用简体中文。"},
                            {"role": "user", "content":  userMessage }
                        ],
                        "stream": false
                    })
                    // JSON.stringify({ prompt: userMessage })
                })
                    .then(response => {
                        const reader = response.body.getReader();
                        const stream = new ReadableStream({
                            start(controller) {
                                function push() {
                                    reader.read().then(({ done, value }) => {
                                        if (done) {
                                            controller.close();
                                            return;
                                        }
                                        controller.enqueue(value);
                                        push();
                                    });
                                }
                                push();
                            }
                        });

                        return new Response(stream, { headers: { 'Content-Type': 'text/html' } });
                    })
                    .then(response => response.text())
                    .then(res => {
                        res = JSON.parse(res);
                        console.log("这个输出文本是什么",res);
                        const botMessageElement = document.createElement('div');
                        botMessageElement.classList.add('message', 'bot');
                        // 这里暂时用写死，后面数据库传来的数据
                        botMessageElement.textContent = res.choices[0].message.content;
                        chatWindow.appendChild(botMessageElement);

                        // 滚动到最新消息
                        chatWindow.scrollTop = chatWindow.scrollHeight;
                    })
                    .catch(error => {
                        console.error('Error:', error);
                    });
                    
                    // const botMessage = `You said: ${userMessage}`;
                    // setTimeout(() => {
                    // const botMessageElement = document.createElement('div');
                    // botMessageElement.classList.add('message', 'bot');
                    // botMessageElement.textContent = botMessage;
                    // chatWindow.appendChild(botMessageElement);
                    //
                    // // 滚动到最新消息
                    // chatWindow.scrollTop = chatWindow.scrollHeight;
                    // }, 500);


                // 清空输入框
                userInput.value = '';
            }
        });

        // 按下回车键发送消息
        userInput.addEventListener('keypress', (e) => {
            if (e.key === 'Enter') {
                sendButton.click();
            }
        });
    });

    // 登出功能
    function logout() {
        alert("You have been logged out.");
        // 这里可以添加实际的登出逻辑，例如清除本地存储的用户信息
    }
</script>
</body>
</html>